package com.ruoyi.fly.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.fly.domain.Reimbursements;
import com.ruoyi.fly.domain.vo.ReimbursementsVo;
import com.ruoyi.fly.mapper.ReimbursementsMapper;
import com.ruoyi.fly.service.ReimbursementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReimbursementsServiceImpl implements ReimbursementsService {

    @Autowired
    private ReimbursementsMapper reimbursementsMapper;

    @Override
    public Reimbursements selectReimbursementsById(String id) {
        return reimbursementsMapper.selectReimbursementsById(id);
    }

    @Override
    public List<Reimbursements> selectReimbursementsList(Reimbursements reimbursements) {
        return reimbursementsMapper.selectReimbursementsList(reimbursements);
    }

    /**
     * 报销审核
     * @param reimbursementsVo 报销
     * @return
     */
    @Override
    public R updateReimbursements(ReimbursementsVo reimbursementsVo) {
        Reimbursements reimbursements1 = new Reimbursements();
        Reimbursements reimbursements = reimbursementsMapper.selectReimbursementsById(reimbursementsVo.getId());
        if (reimbursements.getStatus() == 0){
            return R.fail("该报销单审核中");
        }else if (reimbursements.getStatus() == 1){
           return R.ok(reimbursementsMapper.updateReimbursements(reimbursementsVo));
        }else if (reimbursements.getStatus()==2){
            reimbursementsMapper.updateReimbursements(reimbursementsVo);
            return R.fail("该报销单未通过");
        }
        return null;
    }

    @Override
    public R deleteReimbursementsById(String id) {
        return reimbursementsMapper.deleteReimbursementsById(id)>0?R.ok("删除成功"):R.fail("操作失败");
    }

    @Override
    public R deleteReimbursementsByIds(String[] id) {
        return reimbursementsMapper.deleteReimbursementsByIds(id)>0?R.ok("删除成功"):R.fail("操作失败");
    }
}
